package com.cea.papyrus.multidiagram.actions;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.actions.RetargetAction;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import com.cea.papyrus.multidiagram.extension.ActionBarButtonDescriptor;

/**
 * Create a retarget action with specified parameters.
 */
public class CreateDiagramRetargetAction extends RetargetAction {

	/**
	 * Creates a new CreateDiagramRetargetAction
	 * @param actionID ID of this retarget action
	 * @param label label of the button 
	 * @param tooltip tooltip of the button
	 * @param PLUGIN_ID ID of the plugin that defines the action
	 * @param image image associated to the button
	 * @param disabledImage disabled image for the button
	 */
	public CreateDiagramRetargetAction(String actionID, String label, String tooltip, 
			String PLUGIN_ID, String image, String disabledImage) {
		super(actionID, label);
		setToolTipText(tooltip);
		ImageDescriptor imageDescriptor;
		if(image !=null) {
			imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, image);
			setImageDescriptor(imageDescriptor);
		}
		if( disabledImage != null) {
			imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, disabledImage);
			setDisabledImageDescriptor(imageDescriptor);
		}
	}

	/**
	 * Creates a new CreateDiagramRetargetAction
	 * @param buttonDescriptor descriptor of the button
	 */
	public CreateDiagramRetargetAction(ActionBarButtonDescriptor buttonDescriptor) {
		super(buttonDescriptor.getActionID(), buttonDescriptor.getCreateDiagramLabel());
		setToolTipText(buttonDescriptor.getCreateDiagramTooltip());

		String image = buttonDescriptor.getCreateDiagramImage();
		ImageDescriptor imageDescriptor;
		if(image !=null) {
			imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(buttonDescriptor.getPluginID(), image);
			setImageDescriptor(imageDescriptor);
		}
		image = buttonDescriptor.getCreateDiagramDisableImage();
		if( image != null) {
			imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(buttonDescriptor.getPluginID(), image);
			setDisabledImageDescriptor(imageDescriptor);
		}
	}

}
